<template>
  <!-- 我的收藏 -->
  <div>
    <table border="1px" cellspacing="0">
      <tr align="center">
        <td>编号</td>
        <td>名字</td>
        <td>操作</td>
      </tr>
      <tr v-for="(i, index) in list" :key="index" align="center">
        <td>{{ i.id }}</td>
        <td>{{ i.shops_name }}</td>
        <td>
          <van-button type="primary" color="pink" @click="del(i.id)"
            >删除</van-button
          >
        </td>
      </tr>
    </table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      id: this.$route.query.id,
      user_id: localStorage.getItem("id"),
      list: [],
    };
  },
  mounted() {},
  methods: {
    // 获取收藏
    submit: function () {
      this.myaxios(this.weburl + "user/collect/", "get").then((data) => {
        console.log(data);
        if (data.code == 200) {
          this.list = data.data;
          console.log(this.list);
          this.$toast.success(data.msg);
        } else {
          this.$toast.fali(data.msg);
        }
      });
    },
    // 取消收藏
    del: function (id) {
      this.myaxios(this.weburl + "user/collect/" + id, "delete", {
        user_id: this.user_id,
      }).then((data) => {
        console.log(data);
        if (data.code == 200) {
          this.$toast.success(data.msg);
          this.submit();
        } else {
          this.$toast.fail(data.msg);
        }
      });
    },
  },
  created() {
    this.submit();
  },
};
</script>

<style scoped>
</style>